home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 001 / matlab / Scripts / LinEqns next >
Text File  |  1994-03-24  |  1KB  |  36 lines

  1. // function - call with matrices A and B for solution X of AX=B
  2. disp(['solution of the linear equation AX=B'])
  3. A
  4. B
  5. T1=['the system is determinate with solution:'];
  6. T2=['the system is over-determined:'];
  7. T3=['least-squares solution:'];
  8. T4=['the system is under-determined:'];
  9. T5=['the solution is not unique:'];
  10. T6=['minimal length solution:'];
  11. T7=['any multiple(s) of the following'];
  12. T8=['ortho-normal vector(s) can be added:'];
  13. [M,N]=size(A); [U,S,V]=svd(A); S=diag(S); R=0;
  14. tol=size(S)*S(1)*eps;
  15. for I=1:size(S), if S(I)>tol, R=R+1; end
  16. if R=0, disp(['rank(A)=0: return']), return
  17. if R>0, disp(['rank(A)']),R
  18. S=diag(ones(R,1)./S(1:R));
  19. P=V(:,1:R)*S*U(:,1:R)';
  20. PCOND=S(1,1)\S(R,R);
  21. PCOND
  22. X=P*B;
  23. if M=N, if R=M, disp(T1), X
  24. if M=N, if R<M, disp(T2), disp(T3), X
  25. if M>N, if R=N, disp(T2), X
  26. if M>N, if R<N, disp(T2), disp(T3), X
  27. if M>N, if R<N, disp(T7), disp(T8), ONV=V(:,(R+1):N); ONV
  28. if M<N, if R=M, disp(T4), disp(T5), disp(T6), X
  29. if M<N, if R<M, disp(T2), disp(T3), X
  30. if M<N, disp(T7), disp(T8), ONV=V(:,(R+1):N); ONV
  31. disp(['check C=AX-B'])
  32. C=A*X-B; C
  33. if M>N, if R<N, disp(['check C=A*ONV']), C=A*ONV; C
  34. if M<N, disp(['check C=A*ONV']), C=A*ONV; C
  35. return
  36.